<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Standbox {
            constructor(fakeWindow) {
                this.originWindow = window
                this.window = fakeWindow || {};
                this.proxy = null
                this.init()
            }

            init() {
                this.proxy = new Proxy(this.window, {
                    get(target, key, val) {
                        return Reflect.get(target, key, val)
                    },
                    set(target, key, val) {
                        return Reflect.set(target, key, val)
                    }
                })
            }

        }

        let standbox1 = new Standbox();
        let standbox2 = new Standbox();

        ((window) => { window.a = 1; console.log(window.a) })(standbox1.proxy);
        ((window) => { window.a = 4; console.log(window.a) })(standbox2.proxy)

    </script>
</body>
</html>

<!-- https://www.cnblogs.com/tugenhua0707/p/10306793.html --></meta>